﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FileControl.cs" company="">
//   
// </copyright>
// <summary>
//   The file control.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.Controls
{
    using System;

    /// <summary>
    /// The file control.
    /// </summary>
    public partial class FileControl : FileBaseControl
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="FileControl"/> class.
        /// </summary>
        public FileControl()
        {
            InitializeComponent();
            DragHandler.AddControl(imgIcon);
            DragHandler.AddControl(lblFileName);
            DropHandler.AddControl(imgIcon);
            DropHandler.AddControl(lblFileName);
        }

        #endregion

        #region Public Properties

        public bool ShowToolTip
        {
            get
            {
                return ToolTip.Active;
            }

            set
            {
                ToolTip.Active = value;
            }
        }

        /// <summary>
        /// Gets or sets the details text.
        /// </summary>
        public override string DetailsText
        {
            get
            {
                return ToolTip.GetToolTip(lblFileName);
            }

            set
            {
                ToolTip.SetToolTip(lblFileName, value);
            }
        }

        /// <summary>
        /// Gets or sets the text.
        /// </summary>
        public override string Text
        {
            get
            {
                return lblFileName.Text;
            }

            set
            {
                lblFileName.Text = value;
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// The on file path changed.
        /// </summary>
        protected override void OnFilePathChanged()
        {
            base.OnFilePathChanged();
            if (FilePath == null)
            {
                imgIcon.Visible = false;
            }
            else
            {
                imgIcon.Visible = false;
            }
        }

        /// <summary>
        /// The lbl file name_ double click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void lblFileName_DoubleClick(object sender, EventArgs e)
        {
            if (EditButton.Enabled && EditButton.Visible)
            {
                EditButton.PerformClick();
            }
        }

        #endregion
    }
}